package com.chenhs.oop.study.简单的算法;

import java.util.Arrays;

/**
 * @program: JAVA300
 * @description: 冒泡排序
 * @author: peanut
 * @create: 2018-12-23 21:50
 */
public class TestBubbel {
    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4, 2, 34, 1, 6, 8, 224, 76, 0, -1, -32};
        TestBubbel testBubbel = new TestBubbel();
        testBubbel.bubble((a));
    }

    private void bubble(int[] a) {
        int mainNumber ;
        for (int i = 0; i < a.length - 1; i++) {
            boolean flag=true;
            for (int j = i; j < a.length - 1; j++) {
                if (a[i] < a[j]) {
                    mainNumber = a[j];
                    a[j] =  a[i];
                    a[i]=mainNumber;
                    flag=false;
                }
            }
            if (flag==true){
                break;
            }
        }
        System.out.println(Arrays.toString(a));
    }

}
